package git.determinal.template;

import git.determinal.template.dao.impl.UserDaoImpl;
import git.determinal.template.service.UserService;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * @Description
 * @Author determinal
 * @Date 2024/6/20 上午11:55
 */
public class BeanFactoryTest {
    public static void main(String[] args) {
        // 创建工厂对象
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        // 创建读取器（xml文件）
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
        // 读取配置文件给工厂
        reader.loadBeanDefinitions("beans.xml");
        // 根据id获取Bean实例对象
        UserService userService = (UserService) beanFactory.getBean("userService");
//        System.out.println(userService);

        UserDaoImpl userDao = (UserDaoImpl) beanFactory.getBean("userDao");
//        System.out.println(userDao);
    }
}
